package com.ruoyi.web.controller.postscript;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.postscript.domain.Postscript;
import com.ruoyi.postscript.service.IPostscriptService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务附言Controller
 *
 * @author ruoyi
 * @date 2025-05-09
 */
@RestController
@RequestMapping("/postscript/postscript")
public class PostscriptController extends BaseController
{
    @Autowired
    private IPostscriptService postscriptService;

    /**
     * 查询任务附言列表
     */
    @PreAuthorize("@ss.hasPermi('postscript:postscript:list')")
    @GetMapping("/list")
    public List<Postscript> list(Postscript postscript)
    {
        List<Postscript> list = postscriptService.selectPostscriptList(postscript);
        return list;
    }

    /**
     * 导出任务附言列表
     */
    @PreAuthorize("@ss.hasPermi('postscript:postscript:export')")
    @Log(title = "任务附言", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Postscript postscript)
    {
        List<Postscript> list = postscriptService.selectPostscriptList(postscript);
        ExcelUtil<Postscript> util = new ExcelUtil<Postscript>(Postscript.class);
        return util.exportExcel(list, "任务附言数据");
    }

    /**
     * 获取任务附言详细信息
     */
    @PreAuthorize("@ss.hasPermi('postscript:postscript:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(postscriptService.selectPostscriptById(id));
    }

    /**
     * 新增任务附言
     */
    @PreAuthorize("@ss.hasPermi('postscript:postscript:add')")
    @Log(title = "任务附言", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Postscript postscript)
    {
        return toAjax(postscriptService.insertPostscript(postscript));
    }

    /**
     * 修改任务附言
     */
    @PreAuthorize("@ss.hasPermi('postscript:postscript:edit')")
    @Log(title = "任务附言", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Postscript postscript)
    {
        postscript.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(postscriptService.updatePostscript(postscript));
    }

    /**
     * 删除任务附言
     */
    @PreAuthorize("@ss.hasPermi('postscript:postscript:remove')")
    @Log(title = "任务附言", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(postscriptService.logicDeletePostscript(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
